package com.weixing.mall.provider.controller.admin;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.model.domain.MessageType;
import com.weixing.mall.provider.model.dto.MessageTypeDto;
import com.weixing.mall.provider.service.IMessageTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author wx
 * @Date 2019/11/22 16:44
 * @Version 1.0
 */
@RestController
@RequestMapping("messageType")
@Api(value = "消息类别Api",tags = "消息类别")
public class MessageTypeController extends BaseController {
    @Autowired
    private IMessageTypeService messageTypeService;

    @ApiOperation("查询")
    @GetMapping("")
    public Result selectList(){
        return ResultUtil.success(messageTypeService.getList());
    }

    @ApiOperation("新增类别")
    @PostMapping
    public Result save(MessageTypeDto messageTypeDto){
        messageTypeService.save(messageTypeDto);
        return ResultUtil.success();
    }

    @ApiOperation("修改状态")
    @PostMapping("updatedStatus")
    public Result updatedStatus(Long id, Integer isEnable){
        MessageType messageType = new MessageType();
        messageType.setId(id);
        messageType.setIsEnable(isEnable);
        messageTypeService.updateById(messageType);
        return ResultUtil.success();
    }

    @ApiOperation("删除")
    @PostMapping("del/{id}")
    public Result del(@PathVariable Long id){
        return messageTypeService.removeById(id)  ? ResultUtil.success() : ResultUtil.error();
    }
}
